<?php
namespace app\demo\controller;


use think\Request;
use think\Controller;
use View;
use Db;
use Session;

class Common extends Controller
{


    protected $beforeActionList = [
        'first',
    ];


    public function first(){



    }

    public function login(){


        return $this->fetch();
    }


    public function loginDo(Request $request){

        $param = $request->param();

        $userInfo = Db::table('qi_user')->where('username',$param['username'])->find();


        if(empty($userInfo)){
            return $this->error('帐号不存在或密码错误!');
        }

        if($userInfo['password'] != $param['password']){
            return $this->error('帐号不存在或密码错误!');
        }

        $loginInfo = [
            'username'=>$userInfo['username'],
            'remark'=>$userInfo['remark'],
        ];

        Session::set('loginInfo', $loginInfo);


        return $this->redirect('/demo/Manage/home');



    }

    public function welcome(){


        $userDatas = [
            ['name'=>'zhangsan','sex'=>'1'],
            ['name'=>'lisi','sex'=>'2'],
            ['name'=>'wangwu','sex'=>'2'],
        ];

        $this->assign('users', $userDatas);


       return $this->fetch();
    }


}